package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.saas.constant.StringConstant;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 列表搜索框内容
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/13 15:56
 * @since v1.0
 */
@Getter
public enum PlaceholderEnum {
    // 列表搜索框内容
    CUSTOMER(XbbRefTypeEnum.CUSTOMER.getCode(), null, "enum.placeholder.name.customer",""),
    CUSTOMER_FOCUS(XbbRefTypeEnum.CUSTOMER_FOCUS.getCode(), null, "enum.placeholder.name.customer_focus",""),
    CUSTOMER_DEAL(XbbRefTypeEnum.CUSTOMER_DEAL.getCode(), null, "enum.placeholder.name.customer_focus",""),
    CUSTOMER_FOLLOW(XbbRefTypeEnum.CUSTOMER_FOLLOW.getCode(), null, "enum.placeholder.name.customer_focus",""),
    CUSTOMER_PUBLIC(XbbRefTypeEnum.CUSTOMER_PUBLIC.getCode(), null, "enum.placeholder.name.customer_focus",""),
    CUSTOMER_RECYCLE(XbbRefTypeEnum.CUSTOMER_RECYCLE.getCode(), null, "enum.placeholder.name.customer_focus",""),
    CUSTOMER_NEARBY(XbbRefTypeEnum.CUSTOMER_NEARBY.getCode(), null, "enum.placeholder.name.customer_focus",""),
    CONTACT(RedundantTemplateTypeEnum.CONTACT.getCode(), null, "enum.placeholder.name.contact",""),
    CUSTOMER_COMMUNICATE(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), null, "enum.placeholder.name.customer_communicate",""),
    SUPPLIER_COMMUNICATE(XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(), null, "enum.placeholder.name.supplier_communicate",""),
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), null, "enum.placeholder.name.contract",""),
    SALES_OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), null, "enum.placeholder.name.sales_opportunity",""),
    KEY_OPPORTUNITY(XbbRefTypeEnum.KEY_OPPORTUNITY.getCode(), null, "enum.placeholder.name.sales_opportunity",""),
    ALL_OPPORTUNITY(XbbRefTypeEnum.ALL_OPPORTUNITY.getCode(), null, "enum.placeholder.name.sales_opportunity",""),
    WORK_REPORT(XbbRefTypeEnum.WORK_REPORT.getCode(), null, "enum.placeholder.name.work_report",""),
    SUPPLIER(XbbRefTypeEnum.SUPPLIER.getCode(), null, "enum.placeholder.name.supplier",""),
    SUPPLIER_CONTACT(RedundantTemplateTypeEnum.SUPPLIER_CONTACT.getCode(), null, "enum.placeholder.name.supplier_contact",""),
    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), null, "enum.placeholder.name.purchase",""),
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), null, "enum.placeholder.name.returned_purchase",""),
    BOMBILL(XbbRefTypeEnum.BOM_BILL.getCode(), null, "enum.placeholder.name.bombill",""),
    PRODUCTIONORDER(XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), null, "enum.placeholder.name.productionorder",""),
    PAYMENT(XbbRefTypeEnum.PAYMENT.getCode(), null, "enum.placeholder.name.payment",""),
    PAY_PLAN(XbbRefTypeEnum.PAY_PLAN.getCode(), null, "enum.placeholder.name.pay_plan",""),
    INVOICE(XbbRefTypeEnum.INVOICE.getCode(), null, "enum.placeholder.name.invoice",""),
    PURCHASE_INVOICE(XbbRefTypeEnum.PURCHASE_INVOICE.getCode(), null, "enum.placeholder.name.purchase_invoice",""),
    ASSEMBLE(XbbRefTypeEnum.ASSEMBLE.getCode(), null, "enum.placeholder.name.assemble",""),
    INSTOCK(XbbRefTypeEnum.INSTOCK.getCode(), null, "enum.placeholder.name.instock",""),
    PURCHASE_INSTOCK(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), null, "enum.placeholder.name.purchase_instock",""),
    REFUND_INSTOCK(XbbRefTypeEnum.REFUND_INSTOCK.getCode(), null, "enum.placeholder.name.refund_instock",""),
    OTHER_INSTOCK(XbbRefTypeEnum.OTHER_INSTOCK.getCode(), null, "enum.placeholder.name.other_instock",""),
    PRODUCTION_INSTOCK(XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(), null, "enum.placeholder.name.production_instock",""),
    RETURNED_MATERIEL_INSTOCK(XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(), null, "enum.placeholder.name.returned_materiel_instock",""),
    OUTSTOCK(XbbRefTypeEnum.OUTSTOCK.getCode(), null, "enum.placeholder.name.outstock",""),
    CONTRACT_OUTSTOCK(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), null, "enum.placeholder.name.contract_outstock",""),
    RETURNED_PURCHASE_OUTSTOCK(XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), null, "enum.placeholder.name.returned_purchase_outstock",""),
    OTHER_OUTSTOCK(XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(), null, "enum.placeholder.name.other_outstock",""),
    PRODUCTION_MATERIEL_OUTSTOCK(XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), null, "enum.placeholder.name.production_materiel_outstock",""),
    WORK_ORDER_OUTSTOCK(XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), null, "enum.placeholder.name.work_order_outstock",""),
    INVENTORY(XbbRefTypeEnum.INVENTORY.getCode(), null, "enum.placeholder.name.inventory",""),
    TRANSFER(XbbRefTypeEnum.TRANSFER.getCode(), null, "enum.placeholder.name.transfer",""),
    WAREHOUSE(XbbRefTypeEnum.WAREHOUSE.getCode(), null, "enum.placeholder.name.warehouse",""),
    WAIT_OUTSTOCK(XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(), null, "enum.placeholder.name.wait_outstock",""),
    WAIT_INSTOCK_PURCHASE(XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(), null, "enum.placeholder.name.wait_outstock",""),
    WAIT_PURCHASE(XbbRefTypeEnum.WAIT_PURCHASE.getCode(), null, "enum.placeholder.name.wait_outstock",""),
    SMART_REPLENISHMENT(XbbRefTypeEnum.SMART_REPLENISHMENT.getCode(), null, "enum.placeholder.name.wait_outstock",""),
    WAIT_PRODUCE(XbbRefTypeEnum.WAIT_PRODUCE.getCode(), null, "enum.placeholder.name.wait_outstock",""),
    PRODUCT(XbbRefTypeEnum.PRODUCT.getCode(), null, "enum.placeholder.name.product",""),
    STOCK_SEARCH(XbbRefTypeEnum.STOCK_SEARCH.getCode(), null,  "enum.placeholder.name.stock_search", ""),
    WARNING_SEARCH(XbbRefTypeEnum.WARNING_SEARCH.getCode(), null,  "enum.placeholder.name.stock_search", ""),
    GUARANTEE_SEARCH(XbbRefTypeEnum.GUARANTEE_SEARCH.getCode(), null,  "enum.placeholder.name.stock_search", ""),
    REFUND(XbbRefTypeEnum.REFUND.getCode(), null,  "enum.placeholder.name.refund", ""),
    WORK_ORDER(XbbRefTypeEnum.WORK_ORDER.getCode(), null,  "enum.placeholder.name.work_order", ""),
    WORK_ORDER_ROB(XbbRefTypeEnum.WORK_ORDER_ROB.getCode(), null,  "enum.placeholder.name.work_order", ""),
    QUOTATION(XbbRefTypeEnum.QUOTATION.getCode(), null,  "enum.placeholder.name.quotation", ""),
    PAYMENT_SHEET(XbbRefTypeEnum.PAYMENT_SHEET.getCode(), null, "enum.placeholder.name.payment_sheet",""),
    PREPAYMENT_BALANCE(XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), DistributorMarkEnum.OTHER.getCode(), "enum.placeholder.name.customer",""),
    PREPAYMENT_BALANCE_DISTRIBUTOR(XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), DistributorMarkEnum.DISTRIBUTOR.getCode(), "enum.placeholder.name.distributor",""),
    ONLINE_PAYMENT_FLOW(XbbRefTypeEnum.ONLINE_PAYMENT_FLOW.getCode(), null, "enum.placeholder.name.online_payment_flow",""),
    REIMBURSEMENT_FORM(XbbRefTypeEnum.REIMBURSEMENT_FORM.getCode(), null, "enum.placeholder.name.reimbursement_form",""),
    EXPENSE(XbbRefTypeEnum.EXPENSE.getCode(), null, "enum.placeholder.name.expense",""),
    PAY_SHEET(XbbRefTypeEnum.PAY_SHEET.getCode(), null, "enum.placeholder.name.pay_sheet",""),
    CREDIT_LIMIT(XbbRefTypeEnum.CREDIT_LIMIT.getCode(), null, "enum.placeholder.name.credit_limit",""),
    CREDIT_FIXED_LIMIT(XbbRefTypeEnum.CREDIT_FIXED_LIMIT.getCode(), null, "enum.placeholder.name.credit_fixed_limit",""),
    CREDIT_TEMPORARY_LIMIT(XbbRefTypeEnum.CREDIT_TEMPORARY_LIMIT.getCode(), null, "enum.placeholder.name.credit_temporary_limit",""),
    PREPAY_BALANCE(XbbRefTypeEnum.PREPAY_BALANCE.getCode(), null, "enum.placeholder.name.supplier",""),
    PRODUCT_SEARCH(XbbRefTypeEnum.STOCK_FLOW_BILL.getCode(), null, "enum.placeholder.name.product_search",""),
    BATCH_FLOW_BILL(XbbRefTypeEnum.BATCH_FLOW_BILL.getCode(), null, "enum.placeholder.name.batch_flow_bill",""),
    SEQ_SEARCH(XbbRefTypeEnum.SEQ_SEARCH.getCode(), null, "enum.placeholder.name.seq_search",""),
    MARKET_ACTIVITY(XbbRefTypeEnum.MARKET_ACTIVITY.getCode(), null,"enum.placeholder.name.market_activity",""),
    ALL_CLUE(XbbRefTypeEnum.ALL_CLUE.getCode(), null,"enum.placeholder.name.all_clue",""),
    CLUE_PUBLIC(XbbRefTypeEnum.CLUE_PUBLIC.getCode(), null,"enum.placeholder.name.clue_public",""),
    CLUE_RECYCLE(XbbRefTypeEnum.CLUE_RECYCLE.getCode(), null,"enum.placeholder.name.clue_recycle",""),
    DISTRIBUTOR_MANAGEMENT(XbbRefTypeEnum.DISTRIBUTOR_MANAGEMENT.getCode(), null, "enum.placeholder.name.distributor",""),
    MARKETING_ACTIVITY_MANAGEMENT(XbbRefTypeEnum.MARKETING_ACTIVITY_MANAGEMENT.getCode(), null, "enum.placeholder.name.marketing_activity_management",""),
    PROMOTION_ACTIVITY_MANAGEMENT(XbbRefTypeEnum.PROMOTION_ACTIVITY_MANAGEMENT.getCode(), null, "enum.placeholder.name.promotion_activity_management",""),
    DISTRIBUTOR_ACCOUNT(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(), null, "enum.placeholder.name.distributor_account",""),
    DISTRIBUTOR_CONTACT(XbbRefTypeEnum.DISTRIBUTOR_CONTACT.getCode(), null, "enum.placeholder.name.distributor_contact",""),
    DISTRIBUTOR_COMMUNICATE(XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode(), null, "enum.placeholder.name.distributor_communicate",""),
    ORDER(XbbRefTypeEnum.ORDER.getCode(), null, "enum.placeholder.name.order",""),
    CUSTOMER_STATEMENT_STATISTIC(XbbRefTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getCode(), null,  "enum.placeholder.name.customer_statement_statistic", ""),
    RETURN(XbbRefTypeEnum.RETURN.getCode(), null, "enum.placeholder.name.return",""),
    WRITE_OFF_RECORD(XbbRefTypeEnum.WRITE_OFF_RECORD.getCode(),null,"enum.placeholder.name.write_off_record",""),
    ORDER_OUTSTOCK(XbbRefTypeEnum.ORDER_OUTSTOCK.getCode(),null,"enum.placeholder.name.order_outstock",""),
    OTHER_INCOME(XbbRefTypeEnum.OTHER_INCOME.getCode(),null,"enum.placeholder.name.other_income",""),
    OTHER_EXPENSE(XbbRefTypeEnum.OTHER_EXPENSE.getCode(),null,"enum.placeholder.name.other_expense",""),
    FUND_TRANSFER(XbbRefTypeEnum.FUND_TRANSFER.getCode(),null,"enum.placeholder.name.fund_transfer",""),
    COST_ADJUST(XbbRefTypeEnum.COST_ADJUST.getCode(),null,"enum.placeholder.name.cost_adjust",""),
    KNOWLEDGE_BASE(XbbRefTypeEnum.KNOWLEDGE_BASE.getCode(),null,"enum.placeholder.name.knowledge_base",""),
    WORK_ORDER_V2(XbbRefTypeEnum.WORK_ORDER_V2.getCode(),null,"enum.placeholder.name.work_order_v2",""),
    SERVICE_PROJECT(XbbRefTypeEnum.SERVICE_PROJECT.getCode(),null,"enum.placeholder.name.service_project",""),
    COMPETITOR(XbbRefTypeEnum.COMPETITOR.getCode(),null,"enum.placeholder.name.competitor",""),
    CONTRACT_COMPARE(XbbRefTypeEnum.CONTRACT_COMPARE_RESULT.getCode(),null,"enum.placeholder.name.contract_compare",""),

    UN_KONW(XbbRefTypeEnum.UNKNOWN.getCode(), null, "",""),
    ;
    private Integer code;
    /**
     * @see DistributorMarkEnum
     * 经销商标识
     * 当该值为null，说明经销商、非经销商通用一套，否则不同类型的获取不同的holder。比如，预收款余额，非经销商的为“客户名称或者客户电话搜索”，经销商的则为“经销商名称或者经销商电话搜索”
     */
    private Integer distributorMark;
    private String name;
    private String alias;

    PlaceholderEnum(Integer code, Integer distributorMark, String name, String alias) {
        this.code = code;
        this.distributorMark = distributorMark;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 通过业务类型和distributorMark获取各业务的placeholder
     * @param code 业务类型
     * @param distributorMark 当该值为null，说明经销商、非经销商通用一套，否则不同类型的获取不同的holder。比如，预收款余额，非经销商的为“客户名称或者客户电话搜索”，经销商的则为“经销商名称或者联系电话搜索”
     * @return com.xbongbong.saas.enums.PlaceholderEnum
     * @since v1.0
     * @version v1.0
     */
    public static PlaceholderEnum getByCode(Integer code, Integer distributorMark) {
        if (Objects.isNull(code)){
            return UN_KONW;
        }
        PlaceholderEnum tempEnum = null;
        for (PlaceholderEnum cacheCode : values()) {
            boolean codeEqual = Objects.equals(code, cacheCode.code);
            boolean distributorMarkEqual = Objects.equals(distributorMark, cacheCode.distributorMark);
            if (codeEqual && distributorMarkEqual) {
                //业务类型，且distributorMark都相同
                return cacheCode;
            } else if (codeEqual) {
                //只有业务类型相同
                tempEnum = cacheCode;
            }
        }
        if (Objects.nonNull(tempEnum)) {
            return tempEnum;
        }
        return UN_KONW;
    }

    /**
     * 获取移动端列表页搜索框的PlaceHolder
     *
     * @param refType 业务类型
     * @param distributorMark 当该值为null，说明经销商、非经销商通用一套，否则不同类型的获取不同的holder。比如，预收款余额，非经销商的为“客户名称或者客户电话搜索”，经销商的则为“经销商名称或者经销商电话搜索”
     * @author GuoJun.HU
     * @since V1.0
     * @return
     * @date 2019/3/25 16:34
     */
    public static Map<String, Object> getAppListSearchPlaceHolder (Integer refType, Integer distributorMark) {
        Map<String, Object> searchMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        Integer businessType4Distributor = XbbRefTypeEnum.transferBusinessType4Distributor(refType, distributorMark);
        PlaceholderEnum placeholderEnum = getByCode(businessType4Distributor, distributorMark);
        if (placeholderEnum != null) {
            searchMap.put(StringConstant.INIT_VALUE, placeholderEnum.getName());
        }
        return searchMap;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
